/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-09-05
 * Time: 8:25
 */
class Solution1 {
    public String removeDuplicates(String s) {
        int n = s.length();
        StringBuilder ret = new StringBuilder();
        char[] s1 = s.toCharArray();

        for(char ch : s1) {
            // 出栈
            if(ret.length() > 0  && ch == ret.charAt(ret.length()-1)) {
                ret.deleteCharAt(ret.length()-1);
            } else {
                ret.append(ch);
            }
        }

        return ret.toString();
    }
}
